package com.zhang.zhangapp.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.bean.user.Bill;
import com.zhang.zhangapp.bean.user.BillItem;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2018/4/23.
 */

public class BillsAdapter extends BaseAdapter {
    private List<Bill> billList;
    private Context context;

    public BillsAdapter(List<Bill> billList, Context context) {
        this.billList = billList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return billList == null ? 0 : billList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh = null;
        if (view == null) {
            vh = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_bills, null);
            x.view().inject(vh, view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }

        Bill bill = billList.get(i);
        String amount = "";
        if ("1".equals(bill.getTransType())) {
            vh.typeImageView.setImageResource(R.mipmap.recharge);
            amount = "+" + bill.getAmount();
        } else {
            vh.typeImageView.setImageResource(R.mipmap.xiaofei);
            amount += "-" + bill.getAmount();
        }
        vh.titleText.setText(bill.getTitle());
        vh.desecTextView.setText(bill.getTransdesc());
        vh.priceTypeTextView.setText(amount);
        vh.timeTextView.setText(bill.getPaytime());
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.item_bill_iamge)
        ImageView typeImageView;
        @ViewInject(R.id.bill_title)
        TextView titleText;
        @ViewInject(R.id.bill_desc)
        TextView desecTextView;
        @ViewInject(R.id.bill_price_type)
        TextView priceTypeTextView;
        @ViewInject(R.id.bill_time)
        TextView timeTextView;
    }
}
